package com.example.module_service.car

import android.app.DatePickerDialog
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_common.view.view.BaseMvvmActivity
import com.example.module_service.R
import com.example.module_service.adapter.CarStopAdapter
import com.example.module_service.databinding.ActivityCarPayBinding
import com.example.module_service.databinding.ActivityCarStopBinding
import com.example.module_service.vm.CarStopViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.util.Calendar

@Route(path = "/car/CarStopActivity")
@AndroidEntryPoint
class CarStopActivity : BaseMvvmActivity<ActivityCarStopBinding>() {
    override fun getLayoutId(): Int =R.layout.activity_car_stop

    private val carStopViewModel: CarStopViewModel by viewModels()
    val carStopAdapter= CarStopAdapter()
    override fun initViews() {

        val calender = Calendar.getInstance()
        val year =calender.get(Calendar.YEAR)
        val month =calender.get(Calendar.MONTH)
        val day =calender.get(Calendar.DAY_OF_MONTH)
        binding.ivDateTime.setOnClickListener {
            val datePickerDialog = DatePickerDialog(this,{_,syear,smonth,sday->
                binding.tvDateTime.text="${syear}/${smonth+1}/${sday}"
                carStopViewModel.getCarStop()
            },year,month,day)
            datePickerDialog.show()
        }
        carStopViewModel.getCarStop()
        binding.rv.adapter=carStopAdapter
        binding.rv.layoutManager= LinearLayoutManager(this)
        carStopViewModel.mSuccessLiveData.observe(this){
            carStopAdapter.data.clear()
            carStopAdapter.data.addAll(it.data.sortedByDescending { it.id })

            carStopAdapter.notifyDataSetChanged()
        }
        carStopViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
    }

    override fun getActivityState(state: Bundle) {
        TODO("Not yet implemented")
    }

    override fun saveActivityState(outState: Bundle) {
        TODO("Not yet implemented")
    }

}